<%--
  Created by IntelliJ IDEA.
  User: Wang
  Date: 2019/7/19
  Time: 9:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
    <title>Title</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">

    <!-- jQuery (Bootstrap 插件需要引入) -->
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <!-- 包含了所有编译插件 -->
    <script src="statics/css/bootstrap.min.css"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcss.com/moment.js/2.24.0/moment-with-locales.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript">
        function fmtBoolean(obj){
            return obj==true?"是":"否";
        }

        $(function(){
            var picker1 = $("#datetimepicker1").datetimepicker({
                format: 'YYYY-MM-DD',
                locale: moment.locale('zh-cn'),
                //minDate: '2016-7-1'
            });
            var picker2 = $('#datetimepicker2').datetimepicker({
                format: 'YYYY-MM-DD',
                locale: moment.locale('zh-cn')
            });
            //动态设置最小值
            picker1.on('dp.change', function (e) {
                picker2.data('DateTimePicker').minDate(e.date);
            });
            //动态设置最大值
            picker2.on('dp.change', function (e) {
                picker1.data('DateTimePicker').maxDate(e.date);
            });
        });
        Date.prototype.format = function(fmt) {
            var o = {
                "M+" : this.getMonth()+1,                 //月份
                "d+" : this.getDate(),                    //日
                "h+" : this.getHours(),                   //小时
                "m+" : this.getMinutes(),                 //分
                "s+" : this.getSeconds(),                 //秒
                "q+" : Math.floor((this.getMonth()+3)/3), //季度
                "S"  : this.getMilliseconds()             //毫秒
            };
            if(/(y+)/.test(fmt)) {
                fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
            }
            for(var k in o) {
                if(new RegExp("("+ k +")").test(fmt)){
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
                }
            }
            return fmt;
        };

        //查询
/*        function chaxun() {
            $('').val('');
            document.forms[0].submit();
        }*/
        var itemId_update;
        //修改用户
        function bianji(itemId) {
            $.ajax({
                url:"/ssmZY_war_exploded/wuliao/chakanid",
                type:"post",
                contentType:"application/x-www-form-urlencoded; charset=utf-8",
                dataType:"json",
                data:{itemId:itemId},
                success:function (data) {
                    $("#xiugaiform").modal("show");
                    $("#itemId1").val(data.itemId);
                    $("#itemCode1").val(data.itemCode);
                    $("#itemDescription1").val(data.itemDescription);
                    $("#itemUom1").val(data.itemUom);
                    $("#startActiveDate1").val(new Date(data.startActiveDate).format("yyyy-MM-dd"));
                    $("#endActiveDate1").val(new Date(data.endActiveDate).format("yyyy-MM-dd"));
                    $("#enabledFlag1").val(fmtBoolean(data.enabledFlag));
                    itemId_update=data.itemId;
                },
                error:function () {
                    alert("获取用户数据失败");
                }
            });
        }
        function sub(id){
            window.location.href="/ssmZY_war_exploded/wuliao/bianji?itemId="+itemId_update;
        }
        //删除用户
        function shanchu(itemId) {
            if(confirm("确定要删除"+itemId+"用户吗？")){
                $.ajax({
                    url:"/ssmZY_war_exploded/wuliao/shanchu",
                    type:"post",
                    contentType:"application/x-www-form-urlencoded; charset=utf-8",
                    dataType:"text",
                    data:{itemId:itemId},
                    success:function () {
                        alert("删除成功！");
                        $("#myform").submit();
                    },
                    error:function () {
                        alert("删除失败");
                    }
                });
            }
        }
    </script>
    <style type="text/css">
        th{
            text-align: center;
        }
    </style>
</head>
<body>
<form class="form-inline" id="myform" action="/ssmZY_war_exploded/wuliao/chakan" method="post">
    <div class="panel panel-default">
        <div class="panel-body">
        <h1>物料管理</h1>
        </div>
    <div class="panel-footer">
        <table height="100">
            <tr>
                <td width="300" >
                    <div class="form-group">
                        <label for="wlbm">物料编码：</label>
                        <input type="text" class="form-control" id="wlbm" placeholder="物料编码">
                    </div>
                </td>
                <td  width="300">
                    <div class="form-group">
                        <label for="wlms">物料描述：</label>
                        <input type="text" class="form-control" id="wlms" placeholder="物料描述">
                    </div>
                </td>
                <td width="300">
                    <div class="form-group">
                        <label for="wldw">物料单位</label>
                        <select id="wldw" class="form-control">
                            <option value="1" >米</option>
                            <option value="2">平方米</option>
                            <option value="3">立方米</option>
                            <option value="4">千克</option>
                            <option value="5">个</option>
                            <option value="6">其他</option>
                        </select>
                    </div>
                </td>
                <td width="150">
                    <button type="reset" class="btn btn-default">重置</button>
                    <button type="submit" class="btn btn-primary">查询</button>
                </td>
            </tr>

            <tr>
                <div class="row">
                    <td  width="450">
                        <div class="form-group">
                            <label>生效时间从：</label>
                            <!--指定 date标记-->
                            <div class='input-group date' id='datetimepicker1'>
                                <input type='text' class="form-control" />
                                <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                            </div>
                        </div>
                    </td>
                    <td  width="450">
                        <div class="form-group">
                            <label>生效时间至：</label>
                            <!--指定 date标记-->
                            <div class='input-group date' id='datetimepicker2'>
                                <input type='text' class="form-control" />
                                <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                            </div>
                        </div>
                    </td>
                </div>
                <td>
                    <div class="form-group">
                        <label for="sfqy">是否启用</label>
                        <select id="sfqy" class="form-control">
                            <option value="1" >是</option>
                            <option value="2" >否</option>
                        </select>
                    </div>
                </td>
                <td>
                    <button type="button" class="btn btn-success" data-toggle="modal" data-target="#addForm">新增</button>
                </td>
            </tr>
        </table>
    </div>
    </div>
    <div class="col-lg-12">
        <table class="table table-bordered" style="text-align: center">
            <thead>
            <tr>
                <th>物料编码</th>
                <th>物料描述</th>
                <th>物料单位</th>
                <th>生效时间从</th>
                <th>生效时间至</th>
                <th>是否启用</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${ssmlist}" var="ssmlist">
                <tr>
                    <td>${ssmlist.itemCode}</td>
                    <td>${ssmlist.itemDescription}</td>
                    <td>${ssmlist.itemUom}</td>
                    <td><fmt:formatDate type="both" value="${ssmlist.startActiveDate}" /></td>
                    <td><fmt:formatDate type="both" value="${ssmlist.endActiveDate}" /></td>
                    <td>${ssmlist.enabledFlag=="true"?"是":"否"}</td>
                    <td>
                        <button type="button" class="btn btn-info" onclick="bianji('${ssmlist.itemId}')">编辑</button>
                        <button type="button" class="btn btn-danger" onclick="shanchu('${ssmlist.itemId}')">删除</button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</form>

<%-- 添加数据 --%>
<form action="tianjia" method="post" id="zengjiaForm">
    <div class="modal fade" id="addForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 id="mytitle11" class="modal-title" id="myModalLabel11">
                        添加用户:
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="itemCode">物料编码</label>
                        <input type="text" class="form-control" name="itemCode" id="itemCode" placeholder="物料编码">
                    </div>
                <div class="form-group">
                    <label for="itemDescription">物料描述</label>
                    <input type="text" class="form-control" name="itemDescription" id="itemDescription" placeholder="物料描述">
                </div>
                <div class="form-group">
                    <label for="itemUom">物料单位</label>
                    <select id="itemUom" class="form-control" name="itemUom">
                        <option value="米" >米</option>
                        <option value="平方米">平方米</option>
                        <option value="立方米">立方米</option>
                        <option value="千克">千克</option>
                        <option value="个">个</option>
                        <option value="其他">其他</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="startActiveDate">生效时间从</label>
                    <input type="date" class="form-control" name="startActiveDate" id="startActiveDate" placeholder="生效时间从">
                </div>
                <div class="form-group">
                    <label for="endActiveDate">生效时间至</label>
                    <input type="date" class="form-control" name="endActiveDate" id="endActiveDate" placeholder="生效时间至">
                </div>
                <div class="form-group">
                    <label for="enabledFlag">是否启用</label>
                    <select id="enabledFlag" class="form-control" name="enabledFlag">
                        <option value="true" >是</option>
                        <option value="false" >否</option>
                    </select>
                </div>
                <button type="button" class="btn btn-info" >返回</button>
                <button type="submit" class="btn btn-info">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>
<%--编辑页面--%>
<form action="wuliao/bianji" method="post" id="biaojiform">
    <div class="modal fade" id="xiugaiform" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 id="mytitle1" class="modal-title" id="myModalLabel1">
                        编辑用户:
                    </h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="itemId1" name="itemId"/>
                <div class="form-group">
                    <label for="itemCode1">物料编码:</label>
                    <input type="text" class="form-control"  id="itemCode1" name="itemCode" placeholder="itemCode" autofocus="autofocus" disabled>
                </div>
                <div class="form-group">
                    <label for="itemDescription1">物料描述</label>
                    <input type="text" class="form-control" id="itemDescription1" name="itemDescription">
                </div>
                <div class="form-group">
                    <label for="itemUom1">物料单位</label>
                    <select id="itemUom1" class="form-control" name="itemUom">
                        <option >米</option>
                        <option >平方米</option>
                        <option >立方米</option>
                        <option >千克</option>
                        <option >个</option>
                        <option >其他</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="startActiveDate1">生效时间从</label>
                    <input type="date" class="form-control" placeholder="生效时间从" id="startActiveDate1" name="startActiveDate">
                </div>
                <div class="form-group">
                    <label for="endActiveDate1">生效时间至</label>
                    <input type="date" class="form-control" placeholder="生效时间至" id="endActiveDate1" name="endActiveDate">
                </div>
                <div class="form-group">
                    <label for="enabledFlag1">是否启用</label>
                    <select id="enabledFlag1" class="form-control" name="enabledFlag">
                        <option >是</option>
                        <option >否</option>
                    </select>
                </div>
                <button type="button" class="btn btn-info" data-dismiss="modal">返回</button>
                <button type="button" class="btn btn-danger" onclick="sub('${itemId}')">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>

<!-- 显示分页信息 -->
<div class="row">
    <!-- 分页文字信息 -->
    <div class="col-md-6">
        当前${pageInfo.pageNum}页,总${pageInfo.pages}页,总${pageInfo.total }条记录
    </div>
    <!-- 分页条信息 -->
    <div class="col-md-6">
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <li><a href="/ssmZY_war_exploded/wuliao/emps?pn=1">首页</a></li>
                <c:if test="${pageInfo.hasPreviousPage}">
                    <li>
                        <a href="/ssmZY_war_exploded/wuliao/emps?pn=${pageInfo.pageNum-1}" aria-label="Previous">
                            <span aria-hidden="true">«</span>
                        </a>
                    </li>
                </c:if>
                <c:forEach items="${pageInfo.navigatepageNums}" var="page_Num">
                    <c:if test="${page_Num == pageInfo.pageNum }">
                        <li class="active"><a href="#">${page_Num}</a></li>
                    </c:if>
                    <c:if test="${page_Num != pageInfo.pageNum }">
                        <li><a href="/ssmZY_war_exploded/wuliao/emps?pn=${page_Num}">${page_Num}</a></li>
                    </c:if>
                </c:forEach>
                <c:if test="${pageInfo.hasNextPage}">
                    <li>
                        <a href="/ssmZY_war_exploded/wuliao/emps?pn=${pageInfo.pageNum+1}" aria-label="Next">
                            <span aria-hidden="true">»</span>
                        </a>
                    </li>
                </c:if>
                <li><a href="/ssmZY_war_exploded/wuliao/emps?pn=${pageInfo.pages}">末页</a></li>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>
